package com.rw.coco.handler.message.reply.handler.command.sender;

import com.rw.coco.api.data.CacheMapper;
import com.rw.coco.api.data.PersistenceMapper;
import com.rw.coco.api.data.TransactionSwitch;
import com.rw.coco.api.data.model.AccountModel;
import com.rw.coco.api.data.persistence.*;
import com.rw.coco.api.log.CocoLogger;
import com.rw.coco.api.modle.Account;
import com.rw.coco.api.reply.CocoReplyApi;
import com.rw.coco.api.reply.mapper.AdvancedReply;
import com.rw.coco.api.reply.mapper.DiceReply;
import com.rw.coco.api.reply.mapper.EntertainingReply;
import com.rw.coco.api.reply.mapper.OptionReply;
import com.rw.coco.handler.message.event.CocoMessageEvent;
import com.rw.coco.handler.message.reply.util.FrequencyLimit;
import com.rw.coco.util.CocoData;
import com.rw.coco.util.config.*;

/**
 * 基础发送器
 * 由于event里面包含了太多环境变量
 * 内联会导致一行字符超长，换行会非常难看
 * 声明变量变成几行之后又会导致重复代码
 * <p>
 * 所以直接使用sender的模式，在父类把所有会使用到的变量全部都放入属性中
 * 继承sender就能直接使用
 */
public abstract class BaseSender {
    protected final CocoMessageEvent event;

    protected final Account sender;

    protected final AccountModel accountModel;

    protected final String nick;

    protected final CacheMapper cacheMapper;

    protected final CocoLogger cocoLogger;

    protected final PersistenceMapper mapper;

    protected final AccountMapper accountMapper;

    protected final BotMapper botMapper;

    protected final DeckMapper deckMapper;

    protected final GroupMapper groupMapper;

    protected final ObMapper obMapper;

    protected final CharacterMapper characterMapper;

    protected final CharacterPropertyMapper characterPropertyMapper;

    protected final CardMapper cardMapper;

    protected final TransactionSwitch transactionSwitch;

    protected final OptionReply optionReply;

    protected final DiceReply diceReply;

    protected final AdvancedReply advancedReply;

    protected final EntertainingReply entertainingReply;

    protected final CocoData cocoData;

    protected final CocoConfig cocoConfig;

    protected final AnotherNameConfig anotherNameConfig;

    protected final CocoCommandConfig cocoCommandConfig;

    protected final CocoOption cocoOption;

    protected final MainPropName mainPropName;

    protected final FrequencyLimit frequencyLimit;

    public BaseSender(CocoMessageEvent event) {
        this.event = event;
        this.cacheMapper = event.getDataApi().getCacheMapper();
        this.cocoLogger = event.getCocoLogger();
        this.sender = event.getSender();
        this.accountModel = event.getAccountModel();
        this.nick = event.getNick();

        this.cocoData = event.getCocoData();

        this.frequencyLimit = cocoData.getFrequencyLimit();
        this.cocoConfig = cocoData.getCocoConfig();
        this.anotherNameConfig = cocoConfig.getAnotherNameConfig();
        this.cocoCommandConfig = cocoConfig.getCocoCommandConfig();
        this.cocoOption = cocoConfig.getCocoOption();
        this.mainPropName = cocoConfig.getMainPropName();

        this.mapper = event.getDataApi().getPersistenceMapper();

        this.accountMapper = mapper.getAccountMapper();
        this.botMapper = mapper.getBotMapper();
        this.deckMapper = mapper.getDeckMapper();
        this.groupMapper = mapper.getGroupMapper();
        this.obMapper = mapper.getObMapper();
        this.characterMapper = mapper.getCharacterMapper();
        this.characterPropertyMapper = mapper.getCharacterPropertyMapper();
        this.cardMapper = mapper.getCardMapper();
        this.transactionSwitch = mapper.getTransactionSwitch();

        CocoReplyApi replyApi = event.getReplyApi();

        this.optionReply = replyApi.getOptionReply();
        this.diceReply = replyApi.getDiceReply();
        this.advancedReply = replyApi.getAdvancedReply();
        this.entertainingReply = replyApi.getEntertainingReply();
    }
}
